package com.example.service;

import com.example.pojo.Order;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: springboot_rabbitmq
 * @description: 消息发送
 * @author: ChenZhiXiang
 * @create: 2019-06-04 17:07
 **/
@Component
public class OrderSend {

    @Autowired
    private RabbitTemplate template;

    public void sendOrder(Order order){
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(order.getMessageId());
        //                                交换机                      路由key            消息实体   唯一的id
        template.convertAndSend("exchange-order","routingKey-order",order,correlationData);
    }
}
